<?php

require_once 'smarty_lib/Smarty.class.php';
require_once 'lib/DBClass.php';
require_once 'lib/Account.php';
require_once 'lib/Post.php';

$smarty = new Smarty();
$acc = new Account();
$post = new Post();

$smarty->template_dir = 'template/';
$smarty->compile_dir = 'template_c/';

if(!$acc->validate_cookie()){
	$smarty->assign('error','Anda tidak mepunyai akses untuk membuka halaman ini');
	$smarty->display('fuf-login.html');
}else{
	
	$smarty->assign('cookie', $acc->get_cookie());
	$smarty->assign('page','post.html');
	$smarty->assign('title','Artikel');

	$data = $post->get_all_post();

	foreach ($data as $key=>$value) {
		$jdlTag = '';
		$tag = $post->get_all_tag($value['id_post']);
		foreach ($tag as $valueTag) {
			$jdlTag .= $valueTag['jdl_tag'].', ';
		}
		$data[$key]['tag'] = trim(trim($jdlTag), ",");
	}

	$smarty->assign('post', $data);
	//echo "<pre>";print_r($data);exit();



	if (@$_GET['action'] == 'delete') {
		$id = $_GET['id'];
		$delete = $post->deletePost($id);
	}

	$smarty->display('dashboard.html');
}